﻿#region License
/* Copyright (C) 2009 Tim Coulter
 * 
 * This file is part of ExtremeML.
 * 
 * ExtremeML is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License, as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
*/
#endregion

using System.Xml.Linq;

namespace ExtremeML.Sdk.Vml
{
	/// <summary>
	/// Models the Vml drawing element v:fill.
	/// </summary>
	internal class Fill : VmlElement
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="Fill"/> class.
		/// </summary>
		/// <param name="element">An <see cref="XElement"/> to which this instance is bound.</param>
		public Fill(
			XElement element)
			: base(element)
		{
		}

        /// <summary>
        /// Returns the relationship Id of the associated image part, if one exists.
        /// </summary>
        /// <returns>A <see cref="string"/> that contains an image part relationship Id.</returns>
        public string GetImagePartId()
        {
            var attribute = Element.Attribute(Utility.O + "relid");
            return attribute == null ? null : attribute.Value;
        }

        /// <summary>
		/// Enables or disables the use of this element to represent an image.
		/// </summary>
        /// <param name="id">A <see cref="string"/> that specifies the relationship Id of the associated image part.</param>
        public void SetImage(
            string id)
        {
            if (id == null)
            {
                Element.SetAttributeValue(Utility.O + "relid", null);
                Element.SetAttributeValue("size", null);
                Element.SetAttributeValue("aspect", null);
                Element.SetAttributeValue("origin", null);
                Element.SetAttributeValue("position", null);
                Element.SetAttributeValue("recolor", null);
                Element.SetAttributeValue("rotate", null);
                Element.SetAttributeValue("type", null);
            }
            else
            {
                Element.SetAttributeValue(Utility.O + "relid", id);
                Element.SetAttributeValue("size", "0,0");
                Element.SetAttributeValue("aspect", "atLeast");
                Element.SetAttributeValue("origin", "-32767f,-32767f");
                Element.SetAttributeValue("position", "-32767f,-32767f");
                Element.SetAttributeValue("recolor", "t");
                Element.SetAttributeValue("rotate", "t");
                Element.SetAttributeValue("type", "frame");
            }
		}
	}
}